home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Floppyshop 2
/
Floppyshop - 2.zip
/
Floppyshop - 2.iso
/
diskmags
/
4671-5.790
/
dmg-5789
/
stp
/
stos_03.stp
/
stos_03.stp
Wrap
Text File
|
1998-10-23
|
10KB
|
236 lines
STOS FOR STARTERS
PART 3
BY: BRYN JONES
Welcome to this month's Stos tutorial - after last months' you will have
(hopefully) managed to grasp the basics of string variables (and handling
them). This month we're going to be looking at quite a few new commands,
namely: MODE, COLOUR, REPEAT...UNTIL..., IF...THEN...[ELSE], RND, WAIT, PEN,
INKEY$, GOTO, LLIST, RENUM, and NEW/UNNEW. But first I think there's a need to
further explain some of the basics of using Stos...
I know we've covered the LIST command and it's use before, but there are
some more features of the command that need explaining. As you start to create
bigger and more complex programs, you may find that the whole program listing
won't fit into a single screen. Well, to combat this, as you list a program,
you can pause the display by pressing Space - and space again to continue the
listing. Whilst listing, if you wish to edit the section of code on screen,
simply hit Escape - this will bring up the text cursor, and you can edit away!
You can also actually specify which lines you want to list - the format of this
is:-
list FIRST-LAST
FIRST being the first line, and LAST being the last. Or if you want you
can display all the lines from a certain point, like this:-
list FIRST-
Or all the lines up to a point:-
list -LAST
There is also a very similar command to LIST, which is LLIST - this does
exactly the same - except it outputs to a printer, instead of the screen.
Another useful command to know - when using the editor - is NEW. This
will erase the current program from memory - it's always safest to do this
before loading another program from disk, or especially if you want to start
writing a new program. The format of the command is simple (there are no
parameters):-
new
Note that as with LIST, this is a DIRECT COMMAND - so you don't need any
line numbers before the command.
If you find you've accidentally erased a program with NEW, and want to
bring it back, you can type UNNEW - although this can only be used straight
after you've used NEW - i.e. before you've entered any other commands.
Okay, I hope the above was useful to those of you without a manual, who
were having difficulty in general using Stos. Let's continue with the tutorial,
shall we?
First it's probably a good idea to reload last months' little program into
Stos - assuming you saved it of course!
Edit the first line (from last months program) to look like this:-
10 key off : mode 0 : hide : curs off : colour 3,$700
You're probably wondering what the new commands do - let me explain. First
we have MODE - this command allows you to change between resolutions: 0 = Low;
1 = Med; and 2 = High. We want to be in low resolution for this program, so
that's why we've got "mode 0". Whenever Stos switches resolutions, it
automatically clears the screen - this is why we've removed the "cls" from the
first line - there's no need for it anymore.
The second new command we have is COLOUR - this let's you change the
colours of the screen palette. There are 16 colour indexes in Low resolution
(0-15), 4 in Med (0-3), and just 2 in High (0-1). The format of COLOUR is:-
colour INDEX,$RGB
INDEX being, of course, the colour index number. $RGB is the value (i.e.
colour) given to the index. The reason there is a dollar sign before the value
is because it's a Hexadecimal number - don't worry about what this means for
the moment, though - I don't want to start getting into the more complex stuff
just yet! Anyway, back to explaining how to use COLOUR. Each digit of $RGB is
given a value of 0 to 7 - the first digit controls Red intensity, the second
Green, and the third Blue. These three colours are, in fact, the true primary
colours - and not Red, Yellow, and Blue as most would think. It's difficult to
explain just what values give which colours, so it's best to just experiment
and find out for yourself. There should be a Stos listing on the disk called
"COL_TEST.BAS" - if Dave had enough room to fit it in - which will allow you to
mix colours with ease. Just list the program and read the instructions.
In case you're wondering, the reason we're changing colour 3 is because
the colour is the same as the background colour (which is colour 0). If we'd
left it, anything printed with colour 3 wouldn't have shown up.
The next 4 lines (20-50) of the program are the same as the previous
months' - so need to do any editing there.
We're going to insert a new line (55) now. The line should look like
this:-
55 repeat
REPEAT is a new command, or perhaps more accurately, part of a new
command. It is used in conjunction with UNTIL. These commands form a type of
loop - a certain section of code is looped until a condition is met. Like so:-
repeat
[CODE TO LOOP]
until [CONDITION IS MET]
This is an extremely useful type of loop, and is one of the most common.
The UNTIL command comes later on in the program, so I'll describe it in more
detail then.
We need to insert another new line too, so put this in:-
57 C0L0UR=rnd(15) : if C0L0UR=0 then goto 57 else pen C0L0UR
This line serves as an introduction to numeric variables - C0L0UR (note
the "0"s instead of "O"s, which would've turned it into the COLOUR command) is
a numeric variable - you can tell this because there is no dollar sign at the
end of the name, like there is with string variables.
RND(NUM) is used to generate a random number. NUM is the maximum number
to be generated. The command in this case means that C0L0UR is given a value of
0-15 (because, as I've said before, computers count from 0).
IF...THEN... is a very useful instruction. It allows you to check for a
certain condition then, if true, act upon it. The -optional- ELSE (as used in
the above line) is executed if the condition was false. GOTO instructs the
computer to go to a certain line in a program - virtually all programs have at
least one of these tucked away somewhere. The use of the IF...THEN... and GOTO
commands, in this case, are to insure that C0L0UR cannot be given a value of 0
- you'll see why after I've explained the next command. The PEN command tells
the computer to use colour index NUM to print any text:-
pen NUM
So that's why we don't want to give C0L0UR a value of 0 - as this is the
background colour, remember?
In fact, there is probably a better way of coding the above line, and that
is like this:-
57 C0L0UR=rnd(14)+1 : pen C0L0UR
This also insures that a value of 0 isn't returned for C0L0UR - it does
this by generating a random number from 0 to 14, then adding one - giving a
final value of 1-15.
Whatever method you decide to use in the end doesn't matter, it just goes
to show there's virtually always more than one way of going about things.
The next line needed to be altered is line 70:-
70 wait 10
WAIT is very similar to WAIT KEY, except you instruct the computer to wait
for a certain time - instead of until a key is pressed. The time is measured in
50ths of a second - so "wait 50" would pause the program for a second. Without
the WAIT, the program would run too fast - so it's there to slow the program
down a bit!
Another new line now:-
80 until inkey$=" "
This line completes the REPEAT...UNTIL... loop - all the code inbetween
the instructions will be repeated until the condition is met. INKEY$ is what's
called, a RESERVED VARIABLE. It allows you to check for key presses. In this
case we're checking for the Space bar. It is quite often used to check for key
presses in this context:-
repeat : K$=inkey$ : until K$<>""
This assigns the value contained in INKEY$ to K$. Then the "K$<>""" bit
checks to see if K$ -doesn't- equal nothing (nothing being "" in string terms)
- if it equals something (i.e. doesn't equal nothing... are you still with
me?!) then the loop is broken. After the loop is broken you can check for
certain key presses like so (this one checks for "a"):-
if K$ = "a" then [DO WHATEVER]
Just in case you are wondering the "<>" is the actual "doesn't equal"
part. There are several others of these CONDITIONS too - and I'll be listing
them all next month.
The last line to add is:-
90 default
Well that's the program finished, but by now your program listing is
probably looking very untidy with loads of inserted lines - wouldn't it be
great if we could renumber all the lines to step up in tens again? No probs!
Just use the RENUM direct command:-
renum
The above is an example of RENUM in its' most basic form, but there many
other ways to use it:-
renum NUM
This sets the first line of your program to line NUM - all the other lines
will go up in tens from that.
renum NUM,STEP
This is the same as the previous RENUM, except you can define the STEP
increase - i.e. the program line numbers don't have to go up in tens.
renum NUM,STEP,START-END
Again this is the as the previous, except you can choose to just renumber
the lines from START to END - instead of them all.
Anyway, just to recap, this is what your program should look like now
(after you've renumbered it):-
10 key off : mode 0 : hide : curs off : colour 3,$700
20 HELLO$="Hello - I'm Mr "
30 input "Please Input Your Surname:";SURNAME$
40 cls
50 HELLO$=HELLO$+SURNAME$
60 repeat
70 C0L0UR=rnd(15) : if C0L0UR=0 then goto 70 else pen C0L0UR
80 locate 0,12 : centre HELLO$
90 wait 10
100 until inkey$=" "
110 default
That's all for now, see ya next month!